package com.haixiaoke.saas.enterprise.workOrder.controller;

import java.util.List;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.constant.WorkOrderConstants;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.workOrder.domain.WorkOrderPerson;
import com.haixiaoke.saas.workOrder.service.IWorkOrderPersonService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工单人员信息Controller
 *
 * @author xiaolong
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/enterprise/workOrder/person")
public class EnterpriseWorkOrderPersonController extends BaseController {
    @Autowired
    private IWorkOrderPersonService workOrderPersonService;

    /**
     * 查询工单人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderPerson:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(WorkOrderPerson workOrderPerson) {
        startPage();
        workOrderPerson.setTenantId(TenantContext.getTenantId());
        List<WorkOrderPerson> list = workOrderPersonService.selectWorkOrderPersonAndWorkOrder(workOrderPerson);
        return getDataTable(list);
    }


    /**
     * 查询工单人员信息
     */
    @GetMapping("/info")
    @TenantScope
    public AjaxResult info(WorkOrderPerson workOrderPerson) {
        workOrderPerson.setTenantId(TenantContext.getTenantId());
        List<WorkOrderPerson> list = workOrderPersonService.selectWorkOrderPersonAndPendingWorkOrder(workOrderPerson);
        return success(list);
    }

    /**
     * 获取工单人员信息详细信息
     */
    @GetMapping(value = "/{workOrderPersonId}")
    public AjaxResult getInfo(@PathVariable("workOrderPersonId") Long workOrderPersonId) {
        return success(workOrderPersonService.selectWorkOrderPersonByWorkOrderPersonId(workOrderPersonId));
    }

    /**
     * 新增工单人员信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderPerson:add')")
    @PostMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult add(@RequestBody WorkOrderPerson workOrderPerson) {
        workOrderPerson.setCreateBy(getUsername());
        return toAjax(workOrderPersonService.addWorkOrderPerson(workOrderPerson));
    }

    /**
     * 修改工单人员信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderPerson workOrderPerson) {
        return toAjax(workOrderPersonService.updateWorkOrderPerson(workOrderPerson));
    }

    /**
     * 删除工单人员信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderPerson:remove')")
    @DeleteMapping("/{workOrderPersonIds}")
    @TenantScope
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] workOrderPersonIds) {
        return toAjax(workOrderPersonService.deleteWorkOrderPersonByWorkOrderPersonIds(workOrderPersonIds));
    }



}
